package com.ming.dancing.springboot.service;


import com.ming.dancing.springboot.Dao.FilesDAO;
import com.ming.dancing.springboot.entity.Files;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
@Transactional
public class FilesServiceImpl implements  FilesService
{
    @Autowired
    FilesDAO filesDAO;
    @Override
    public List<Files> findallFile() {
        return filesDAO.findallFile();
    }

    @Override
    public void save(Files files ) {
        //userFile.setIsImg()?  //是否是图片 解决方案: 当类型中含有image时说明当前类型一定为图片类型
        String isImg = files.getType().startsWith("image")?"是":"否";
        files.setIsImg(isImg);
        files.setDowncounts(0);
        files.setUploadTime(new Date());
        filesDAO.save(files);
    }

    @Override
    public Files findById(String id) {
        return filesDAO.findById(id);
    }

    @Override
    public void update(Files files) {
        filesDAO.update(files);
    }

    @Override
    public void delete(String id) {
        filesDAO.delete(id);
    }


}
